package com.sk.bilibili.view.activity;

import static com.sk.bilibili.utils.StringUtils.str;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.view.View;
import android.widget.Toast;

import com.sk.bilibili.R;
import com.sk.bilibili.databinding.ActivityLoginBinding;
import com.sk.bilibili.model.activity.LoginModel;
import com.sk.bilibili.utils.StringUtils;

public class LoginActivity extends BaseActivity<ActivityLoginBinding, LoginModel> {

    @Override
    protected void afterSetView() {
        initView();
        bindEvent();
    }

    private void bindEvent() {
        bind.etPassword.setOnFocusChangeListener((v, hasFocus) -> {
            bind.iv22.setImageResource(hasFocus?R.drawable.close22:R.drawable.open22);
            bind.iv33.setImageResource(hasFocus?R.drawable.close33:R.drawable.open33);
        });
        bind.btnLogin.setOnClickListener(v ->
                model.login(str(bind.etPhone),str(bind.etPassword)));
        bind.btnRegister.setOnClickListener(v -> startActivity(RegisterActivity.class));
    }

    private void initView() {
        bind.tvShow.setText(model.getText(getResources().getColor(R.color.pink, getTheme())));
    }

    public void loginSuccess() {
        startActivity(MainActivity.class,true);
    }

    public void loginError() {
        toast("用户名或密码错误");
    }

}